package middle;

public class Solution_287 {

    public int findDuplicate(int[] nums) {
        int next = 0;
        while (true) {
            if (nums[next] == 0) {
                return next;
            } else {
                int n = nums[next];
                nums[next] = 0;
                next = n;
            }
        }
    }
}
